/-boot
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
1
70
 
1
module teapo.app {
2
​
3
  export function run() {
4
    var loadingDiv = document.createElement('div');
5
    loadingDiv.className = 'teapo-boot';
6
    loadingDiv.textContent = loadingDiv.innerText = 'Loading...';
7
​
8
    var pageElement: HTMLElement = null;
9
​
10
    for (var i = 0; i < document.body.childNodes.length; i++) {
11
      var e = <HTMLElement>document.body.childNodes.item(i);
12
      if (e && e.tagName && e.tagName.toLowerCase()
13
        && e.className && e.className.indexOf('teapo-page') >= 0) {
14
​
15
        pageElement = e;
16
        pageElement.appendChild(loadingDiv);
17
        break;
18
​
19
      }
20
    }
21
​
22
​
23
    function start() {
24
​
25
      loadingDiv.textContent = 'Loading storage...';
26
​
27
      var storage: teapo.DocumentStorage = null;
28
      var viewModel: teapo.ApplicationShell = null;
29
​
30
      pageElement.appendChild(loadingDiv);
31
​
32
      function storageLoaded() {
33
​
34
        loadingDiv.textContent += ' rendering...';
35
​
36
        setTimeout(() => {
37
          teapo.registerKnockoutBindings(ko);
38
          (<any>teapo.EditorType).Html.storageForBuild = storage;
39
​
40
          viewModel = new teapo.ApplicationShell(storage);
41
          (<any>window).debugShell = viewModel;
42
​
43
          ko.renderTemplate('page-template', viewModel, null, pageElement);
44
        }, 1);
45
      }
46
​
47
      var forceLoadFromDom = window.location.hash && window.location.hash.toLowerCase() === '#resettodom';
48
​
49
      teapo.openStorage(
50
        {
51
          documentStorageCreated: (error, s) => {
52
            storage = s;
53
            storageLoaded();
54
          },
55
          getType: (fullPath) => teapo.EditorType.getType(fullPath),
56
          getFileEntry: (fullPath) => viewModel.fileList.getFileEntry(fullPath),
57
          setStatus: (text) => loadingDiv.textContent = text
58
        },
59
        forceLoadFromDom);
60
    }
61
​
62
    if (window.addEventListener) {
63
      window.addEventListener('load', start, true);
64
    }
65
    else {
66
      window.onload = start;
67
    }
68
  }
69
​
70
}
0:0